import type { Book, BorrowBook, ReserveBook, Category } from "@/domain/book";
import request from "@/request";

export function getBooks() {
  return request<Book[]>({
    url: "/api/book/getBooks",
    params: {
      pageSize: 10,
      curPage: 0,
    },
  });
}
export function getBooksByIsbn(params: { isbn: string }) {
  return request<Book[]>({
    url: "/api/book/searchByIsbn",
    params,
  });
}
export function getBooksByName(params: { bookName: string }) {
  return request<Book[]>({
    url: "/api/book/searchByBookName",
    params,
  });
}
export function getBooksByAuthor(params: { author: string }) {
  return request<Book[]>({
    url: "/api/book/searchByAuthor",
    params,
  });
}

export function getBook(params: { isbn: string }) {
  return request<Book>({
    url: "/api/book/getBookDetail",
    params,
  });
}

// 借一本书
export function borrowBook(params: any) {
  return request({
    url: "/api/book/borrowBook",
    params,
  });
}
// 借很多本书
export function borrowBooks(params: any) {
  return request({
    url: "/api/book/borrowBooks",
    params,
  });
}

export function renewBook(params: { isbn: string }) {
  return request({
    url: "/api/book/renew",
    params,
  });
}
export function getBorrowBooks() {
  return request<BorrowBook[]>({
    url: "/api/book/getBorrowBooks",
  });
}
export function getAllBorrowBooks() {
  return request<BorrowBook[]>({
    url: "/api/book/getBorrowBooksByAdmin",
    params: {
      pageSize: 10,
      curPage: 0,
    },
  });
}
export function returnBook(params: { id: number; isbn: string }) {
  return request({
    url: "/api/book/returnBook",
    params,
  });
}

export function enableBook(params: { isbn: string }) {
  return request({
    url: "/api/book/enableBook",
    params,
  });
}

export function disableBook(params: { isbn: string }) {
  return request({
    url: "/api/book/disableBook",
    params,
  });
}
export function updateBook(data, headers) {
  return request({
    method: "POST",
    url: "/api/book/updateBook",
    params: {
      originIsbn: data.isbn
    },
    data,
    headers,
  });
}
export function uploadBook(data, headers) {
  return request({
    method: "POST",
    url: "/api/book/uploadBook",
    data,
    headers,
  });
}

// 获取同一 isbn 的所有图书
export function getBooksIncludeBookIdByIsbn(params: { isbn: string }) {
  return request({
    url: "/api/book/getBooksIncludeBookIdByIsbn",
    params: {
      isbn: params.isbn,
      pageSize: 10,
      curPage: 0,
    },
  });
}

// 预约图书的相关 api
export function reserveBook(params: { isbn: string }) {
  return request({
    url: "/api/book/reserve",
    params,
  });
}
export function cancelReserveBook(params: { id: number }) {
  return request({
    url: "/api/book/cancelReserve",
    params,
  });
}
export function getAllReserveBooks() {
  return request<ReserveBook[]>({
    url: "/api/book/reserveBooks",
  });
}
export function getTheReserveBook(params: { isbn: string }) {
  return request({
    url: "/api/book/borrowBookByReservation",
    params,
  });
}

// 返回不同通知的三个请求
export function getOverdueNum(params: any) {
  return request({
    url: "/api/notification/getOverdueNum",
    params,
  })
}
export function getBookWillReturnNum(params: any) {
  return request({
    url: "/api/notification/getBookWillReturnNum",
    params,
  })
}
export function getReservationWillInvalidNum(params: any) {
  return request({
    url: "/api/notification/getReservationWillInvalidNum",
    params,
  })
}

// 付款
export function payMoney(params: { bookId: number }) {
  return request({
    url: "/api/book/payMoney",
    params,
  });
}
// export function alipay(params: { bookId: string }) {
//   return request({
//     url: "/api/ali/pay",
//     params,
//   });
// }

// 有关借阅、预约、付款的历史请求
export function getAllReservationHistory(params: any) {
  return request({
    url: "/api/history/getAllReservationHistory",
    params,
  })
}
export function getReservationHistoryByReaderId(params: any) {
  return request({
    url: "/api/history/getReservationHistoryByReaderId",
    params,
  })
}
export function getAllBorrowHistory(params: any) {
  return request({
    url: "/api/history/getAllBorrowHistory",
    params,
  })
}
export function getRBorrowHistoryByReaderId(params: any) {
  return request({
    url: "/api/history/getRBorrowHistoryByReaderId",
    params,
  })
}
export function getAllFineHistory(params: any) {
  return request({
    url: "/api/history/getAllFineHistory",
    params,
  })
}
export function getRFineHistoryByReaderId(params: any) {
  return request({
    url: "/api/history/getRFineHistoryByReaderId",
    params,
  })
}

// 查看遗失、损坏图书
export function searchLostBooks(params: any) {
  return request({
    url: "/api/book/searchLostBooks",
    params,
  })
}
export function searchDamageBooks(params: any) {
  return request({
    url: "/api/book/searchDamageBooks",
    params,
  })
}

// 书籍分类操作
export function getCategory() {
  return request<Category[]>({
    url: "/api/book/getCategory",
  });
}
export function deleteCategory(params: any) {
  return request({
    url: "/api/book/deleteCategory",
    params,
  })
}
export function addCategory(params: any) {
  return request({
    url: "/api/book/addCategory",
    params,
  }) 
}
export function updateCategory(params: any) {
  return request({
    url: "/api/book/updateCategory",
    params,
  })
}

// 书籍位置相关操作
export function getBookLocation(params: any) {
  return request({
    url: "/api/book/getBookLocation",
    params,
  });
}
export function updateBookLocation(data: any) {
  return request({
    method: 'POST',
    url: "/api/book/updateBookLocation",
    data,
    params: {
      rackNumber: data?.rackNumber
    },
  });
}

// 删除图书
export function deleteBookByIsbn(params: { isbn: string }) {
  return request({
    url: "/api/book/deleteBookByIsbn",
    params,
  });
}
export function deleteBookByBookId(params: { bookId: number }) {
  return request({
    url: "/api/book/deleteBookByBookId",
    params,
  });
}

// 更改图书的损坏和遗失状态
export function setDamage(params: any) {
  return request({
    url: "/api/book/setDamageBook",
    params,
  });
}
export function setLost(params: any) {
  return request({
    url: "/api/book/setLostBook",
    params,
  });
}

